<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<head>
	<title>按目录添加</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>按目录添加</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">采购项目管理</a></li>
            <li class="active"><a href="#">招标目录管理</a></li>
        </ol>
    </section>
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class=" form-inline">
                    <div class="form-group form-group-xs">
                     <label>目录编码：</label>
                        <input class="form-control" type="text" id="drugcatalogCode" placeholder="目录编码" />
                    </div>
                     <div class="form-group form-group-xs">
                        <label>目录名称：</label>
                        <input class="form-control" type="text" id="drugcatalogName" placeholder="目录名称" />
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="txtDrugForm">状态：</label>
                        <select class="form-control"  id="attribute">
                        	<option value="">请选择</option>
                        	<option value="0">国家</option>
                        	<option value="1">省增补</option>
                        </select>
                    </div>
                    <button type="button" class="btn btn-success btn-sm" onclick="search()">查&nbsp;询</button>
                </div>
            </div>
        </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        <div class=" box box-warning bottongroup">
          <a href="javascript:history.go(-1)" class="btn btn-default btn-sm" >返&nbsp;回</a>
        </div>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
    //查询
	function search() {
		var drugcatalogCode = $("#drugcatalogCode").val();
		var drugcatalogName = $("#drugcatalogName").val();
		var attribute = $("#attribute").val();
		$("#gridlist").jqGrid("clearGridData");
			$("#gridlist").jqGrid('setGridParam',{  
			mtype: "POST",
	        datatype:'json',
	        postData:{"drugcatalogCode":drugcatalogCode, "drugcatalogName":drugcatalogName,"attribute":attribute},
	        page : 1
	    }).trigger("reloadGrid"); //重新载入  
	}
        $(function () {
            $("#gridlist").jqGrid({
                url: "${ctx}/bidProject/getImportDrugByCatalogDataList.html?projId=${projId}",
                mtype: "POST",
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: ['操作','drugcatalogId','目录编号', '目录名称','目录开始日期', '目录结束日期', '属性'],
                colModel: [
                    { name: 'operate', width: 80 , align:"center",sortable: false, 
                    	formatter : function(val, opts, rowdata) {
                    	var	str= "";
                    	str += "<a href='javascript:void(0)' onclick=\"submitDrugTOProj('"+rowdata.drugcatalogId+"','${projId}')\" style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat 0px -80px' class='opIcon' title='全部添加'></a>";
                    	str +="<a href='${ctx}/bidProject/toDrugByCatalogList.html?projId=${projId}&drugcatalogId="+rowdata.drugcatalogId+"&drugcatalogName="+rowdata.drugcatalogName+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -20px -80px' class='opIcon' title='逐条添加'></a>";
                    	return str;
                    } },
					{ name: 'drugcatalogId', width: 100,hidden:true , align:"center" ,sortable: false},
                    { name: 'drugcatalogCode', width: 100 , align:"center",sortable: false},
                    { name: 'drugcatalogName', width: 100 , align:"center" ,sortable: false},
                    { name: 'startTime', width: 100 , align:"center" ,sortable: false},
                    { name: 'endTime', width: 100 , align:"center" ,sortable: false},
                    { name: 'attribute', width: 100 , align:"center" ,sortable: false,
                    	formatter : function(val, opts, rowdata) {
                        	return val==1?"省增补":(val==0?"国家":"其他");
                        }
                    }
               
                ],
                
                rowNum: 20,
                rowList: [10, 20, 50, 100],
                rownumbers: true,
                pager: "#gridpage",
                //multiselect: true, 
                viewrecords: true,
                caption: "${name}-未添加药品",
                //序号宽度自动变化
                gridComplete:function(){        
                    var page = $("#gridlist").jqGrid('getGridParam','page');
                    var rows = $('#gridlist').getGridParam("rowNum");
                    var maxnum = (rows*page).toString();
                    var len = (maxnum.length)*10;
                    $('.jqgfirstrow').find('td').eq(0).css('width',len+'px');
                    $('#gridlist_rn').css('width',len+'px');
                },
                jsonReader: {
                    repeatitems: false,
                    id: "drugcatalogId"
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });
        //添加
    	function submitDrugTOProj(drugcatalogId,projId){
    		$.post('${ctx}/bidProject/getDrugCount.html',{"projId":projId,"drugcatalogId":drugcatalogId},function(data){
    			$.HN.message.confirm("已添加"+data.rows[0]+"个,即将添加"+data.rows[1]+"个", '', '').on(function (e) {
 	               if (e) {
 		           	$.ajax({
 						type:"POST",
 						url:"${ctx}/bidProject/importDrugByCatalog.html",
 						data:{"drugcatalogId":drugcatalogId,"projId":projId},
 						dataType:"json",
 						success:function(returnData){
 							if (returnData.success == true) {
 								$("#gridlist").jqGrid("clearGridData");
 			    				$("#gridlist").jqGrid().trigger("reloadGrid");
 			    				$.HN.message.alert("添加成功！", "消息", "success");
 			    			} else {
 			    				$.HN.message.alert("添加失败！", "消息", "error");
 			    			}
 						}
 					});
 	               }
           	 });
    			
    		},'json');
        }
    	
    </script>
</body>
</html>